/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tilegame.sprites;

import graphics.Animation;

/**
 *
 * @author Allan
 */
public class Boy  extends Element {

    private static final float JUMP_SPEED = -.95f;
    
    private boolean onGround;

    public Boy(Animation left, Animation right,
            Animation deadLeft, Animation deadRight) {
        super(left, right, deadLeft, deadRight);
        super.setLife(10);
    }

    public void jump(boolean forceJump) {
        if (onGround || forceJump) {
            onGround = false;
            setVelocityY(JUMP_SPEED);
        }
    }

    public void collideVertical() {
        // check if collided with ground
        if (getVelocityY() > 0) {
            onGround = true;
        }
                setVelocityY(0);
    }

    public void setY(float y) {
        // check if falling
        if (Math.round(y) > Math.round(getY())) {
            onGround = false;
        }
        super.setY(y);
    }

    public float getMaxSpeed() {
        return 0.09f;
    }
}
